package com.yaorange.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yaorange.entity.Article;
import com.yaorange.mapper.ArticleMapper;
import com.yaorange.service.ArticleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description:
 * @company: yaorange
 * @author: 啊啊啊林
 * @version: 1.0
 * @create: 2021-09-23 10:54:19
 */
@Service
@Transactional//事务
public class ArticleServiceImpl implements ArticleService {
    @Resource
    private ArticleMapper articleMapper;


    @Override
    public List<Article> findAll() {
        return articleMapper.selectAll();
    }

    @Override
    public PageInfo<Article> findAllByPage(Integer pageNum, Integer pageSize) {

        PageHelper.startPage(pageNum, pageSize);
        List<Article> articles = articleMapper.selectAllArticle();
        return new PageInfo<>(articles);
    }

    @Override
    public PageInfo<Article> selectByConditonArticle(String goodsName, Integer typeId) {
        PageHelper.startPage(1, 10);

            List<Article> articles = articleMapper.selectAllArticleByCondition("%"+goodsName+"%", typeId);


            return new PageInfo<>(articles);







    }

    @Override
    public int deleteByArticleId(Integer articleId) {
        int i = articleMapper.deleteByPrimaryKey(articleId);
        return i;
    }

    @Override
    public Article selectWindowData(Integer articleId) {
        Article article=articleMapper.selectWindowData(articleId);

        return article;
    }

    @Override
    public int updateArticle(Article article) {
        int i = articleMapper.updateByPrimaryKeySelective(article);
        return i;

    }

    @Override
    public int deleteMany(Integer[] str) {
        int i1=0;
        for (int i = 0; i < str.length; i++) {
           i1 += articleMapper.deleteByPrimaryKey(str[i]);

        }
        return i1;
    }

    @Override
    public int insertNewArticle(Article article) {
        int i = articleMapper.insertSelective(article);
        return i;
    }


}
